package com.hp.wallet.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.wallet.entity.UserWallet;
import com.hp.wallet.service.UserWalletService;
import com.hp.wallet.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;


@RestController
@RequestMapping("userwallet")
public class UserWalletController {

    @Autowired
    private UserWalletService userWalletService;

    /**
     * 查询用户钱包余额
     * @param userId
     * @return
     */
    @RequestMapping("/amount")
    public Result getAmount(@RequestParam(value = "userId") Long userId){
        System.out.println(userId);

        UserWallet user = userWalletService.getOne(new QueryWrapper<UserWallet>().eq("user_id", userId));
        BigDecimal walletAmount = user.getWalletAmount();
        return Result.ok().put("walletAmount",walletAmount);
    }





}
